
/*
Copyright 2009 Peter Ekler, Akos Ludanyi, Budapest University of Technology and Economics, Department of Automation and Applied Informatics, Applied Mobile Research Group (AMORG) http://amorg.aut.bme.hu

This file is part of MobTorrent.

MobTorrent is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

MobTorrent is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with MobTorrent.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ui;

import data.LocalizationSupport;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;

/**
 *
 * @author Tyrael
 */
public class MTDialogYesNo implements CommandListener
{
    public static final int Task_NeedRestart = 1;
    public static final int Task_SearchForUpdate = 2;

    public interface MTDialogYesNoListener
    {
        public void yesSelected(int aTaskCode);
        public void noSelected(int aTaskCode);
    }

    private Alert yesNoAlert;
    private Command softKeyNo;
    private Command softKeyYes;
    private MTDialogYesNoListener yesNoListner;
    private int taskCode;

    public MTDialogYesNo(MTDialogYesNoListener aYesnoListener, String aQuestionText, int aTaskCode)
    {
        yesNoListner = aYesnoListener;
        taskCode = aTaskCode;
        yesNoAlert = new Alert(LocalizationSupport.getMessage("title_dialogYesNo"));
        yesNoAlert.setString(aQuestionText);
        softKeyNo = new Command(LocalizationSupport.getMessage("label_no"), Command.BACK, 1);
        softKeyYes = new Command(LocalizationSupport.getMessage("label_yes"), Command.OK, 1);
        yesNoAlert.addCommand(softKeyNo);
        yesNoAlert.addCommand(softKeyYes);
        yesNoAlert.setCommandListener(this);
    }

    public Displayable getDisplayable()
    {
        return yesNoAlert;
    }

    public void commandAction(Command c, Displayable d)
    {
        if (c.getCommandType() == Command.OK)
        {
            yesNoListner.yesSelected(taskCode);
        }
        else
        {
            yesNoListner.noSelected(taskCode);
        }
    }
};
